package com.itic.mall.mobile.goods;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.utils.StringHelper;
import com.itic.appbase.framework.utils.ValueHelper;
import com.itic.mall.mobile.base.BaseMobileInterface;
import com.itic.mall.mobile.goods.category.CategoryVo;
import com.itic.mall.system.goods.goodscategory.persistence.model.GoodsCategory;
import com.itic.mall.system.goods.goodscategory.persistence.model.GoodsCategoryExample;
import com.itic.mall.system.goods.goodsspu.persistence.model.GoodsSpu;
import com.itic.mall.system.goods.goodsspu.persistence.model.GoodsSpuExample;
import com.itic.mall.system.goods.goodsspu.persistence.model.GoodsSpuExample.Criteria;
import com.itic.mall.system.goods.goodsspu.persistence.vo.ConEmptyVo;
import com.itic.mall.system.market.marketactivity.persistence.model.MarketActivity;
import com.itic.mall.system.market.marketadvert.persistence.model.MarketAdvert;
import com.itic.mall.system.market.marketbanner.persistence.model.MarketBanner;
import com.itic.mall.system.market.marketmodel.persistence.model.MarketModel;
import com.itic.mall.system.market.wordtag.persistence.model.WordTag;
import com.itic.mall.system.market.wordtag.persistence.model.WordTagExample;
import com.itic.mall.system.market.wordtag.service.WordTagService;
import com.itic.mall.system.users.usersmall.persistence.model.UsersMall;

/**
 * 首页模块接口信息
 * 
 * @author 许小宝
 * @time 2017/12/01
 */
@Controller
@RequestMapping(value = "/mobile/goods")
public class GoodsInterface extends BaseMobileInterface {
	
	
	@Autowired
	private WordTagService wordTagService;
	
	
	/**
	 * 获取商品信息
	 * @return
	 */
	@RequestMapping(value = "/getSpuEmptyMsg")
	@ResponseBody
	public Map<String,Object> getSpuEmptyMsg( HttpServletRequest request, HttpServletResponse response, String id ){
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			if( StringHelper.isNotBlank(id) ){
				GoodsSpu goodsSpu = goodsSpuService.get(id);
				if( null != goodsSpu ){
					ConEmptyVo emptyVo = new ConEmptyVo();
					emptyVo.setSpuId(id);
					emptyVo.setGoodsName(goodsSpu.getGoodsName());
					emptyVo.setMainImageUrl(goodsSpu.getMainImageUrl());
					emptyVo.setPrice(goodsSpu.getPrice());
					emptyVo.setConPrice(goodsSpu.getConPrice());
					//dataMap.put("emptySpu", emptyVo);
					//更新商品信息为没有优惠券
					goodsSpu.setCouponMoney(0.00);
					goodsSpuService.edit(goodsSpu);
					resultMap.put(DATA, emptyVo);
					
					errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
				}else{
					errorCode = PRODUCT_DATA_ERROR_CODE;
					errorMsg = PRODUCT_DATA_ERROR_MSG;
				}
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "wordTags", e.toString(), "热词搜索", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
	/**
	 * 获取商品信息
	 * @return
	 */
	@RequestMapping(value = "/getJingxuanList")
	@ResponseBody
	public Map<String,Object> getJingxuanGoods( HttpServletRequest request, HttpServletResponse response ){
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			Map<String, Object> dataMap = new HashMap<String, Object>();
			GoodsSpuExample example = new GoodsSpuExample();
			Criteria criteria = example.createCriteria();
			criteria.andIsEffectiveEqualTo(DBConst.TRUE);// 是否有效
			criteria.andIsShowEqualTo(DBConst.TRUE);// 是否可见
			criteria.andIsJingpingEqualTo(DBConst.TRUE);
			this.handlePageQueryDefault(request, example);// 分页
			int count = goodsSpuService.count(example);// 总条数
			List<GoodsSpu> list = goodsSpuService.list(example);// 数据list
			
			dataMap.put("total", count);
			dataMap.put("isMore", isMore(request, count));
			dataMap.put("list", ValueHelper.tranList2MapList(list,spuIgnoreProperties));
			resultMap.put(DATA, dataMap);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "wordTags", e.toString(), "热词搜索", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
	/**
	 * 分类热词
	 * 
	 * @return
	 */
	@RequestMapping(value = "/wordTags")
	@ResponseBody
	public Map<String,Object> wordTags( HttpServletRequest request, HttpServletResponse response ){
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			
			Map<String, Object> dataMap = new HashMap<String, Object>();
			
			dataMap.put("全部", getWordTagByType("all"));
			dataMap.put("友惠", getWordTagByType("yh"));
			dataMap.put("京东", getWordTagByType("jd"));
			
			resultMap.put(DATA,dataMap);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "wordTags", e.toString(), "热词搜索", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	public List<Map<String, Object>> getWordTagByType( String type ){
		WordTagExample example = new WordTagExample();
		com.itic.mall.system.market.wordtag.persistence.model.WordTagExample.Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		if( StringHelper.isNotBlank(type) ){
			criteria.andTypeLike("%"+type+"%");
		}
		List<WordTag> list = wordTagService.list(example);
		List<Map<String, Object>> mapList = ValueHelper.tranList2MapList(list, new String[] { "id","isEffective","updateTime","orgCode","createUser","reorder","note","createTime","isVisible","type"});
		return mapList;
	}
	
	
	/**
	 * APP首页大分类搜索
	 * 
	 * @return
	 */
	@RequestMapping(value = "/categorys")
	@ResponseBody
	public Map<String, Object> categorys(HttpServletRequest request, HttpServletResponse response,String type) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			
			ArrayList<CategoryVo> categorys = new ArrayList<CategoryVo>();
			
			GoodsCategoryExample example = new GoodsCategoryExample();
	   		example.setOrderByClause("REORDER ASC");
	   		com.itic.mall.system.goods.goodscategory.persistence.model.GoodsCategoryExample.Criteria criteria = example.createCriteria();
	   		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
	   		criteria.andLevelEqualTo("1");
	   		if( StringHelper.isNotBlank(type) ){
	   			criteria.andTypeLike("%"+type+"%"); 
	   		}
	   		List<GoodsCategory> list = goodsCategoryService.list(example);
	   		
	   		if( list.size()>0 ){
	   			for( GoodsCategory temp : list ){
	   				CategoryVo categoryVo = new CategoryVo();
	   				categoryVo.setId(temp.getId());
	   				categoryVo.setName(temp.getName());
	   				categoryVo.setCodeid(temp.getCodeid());
	   		   	    categoryVo.setCategorySubs( getSubCategorysByPcode(temp.getCodeid()) );
	   		   	    categorys.add(categoryVo);
	   			}
	   		}
			resultMap.put(DATA, categorys);
			
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "categorys", e.toString(), "APP首页大分类搜索", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}

	/**
	 * APP首页大分类搜索
	 * 
	 * @return
	 */
	@RequestMapping(value = "/topCategorys")
	@ResponseBody
	public Map<String, Object> topCategorys(HttpServletRequest request, HttpServletResponse response, String type) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			resultMap.put(DATA, getTopCategorysByType(type));
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "categorys", e.toString(), "APP首页大分类搜索", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
	/**
	 * APP首页大分类搜索
	 * 
	 * @return
	 */
	@RequestMapping(value = "/subCategorys")
	@ResponseBody
	public Map<String, Object> subCategorys(HttpServletRequest request, HttpServletResponse response, String id) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			resultMap.put(DATA, getSubCategorysByPid(id));
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "categorys", e.toString(), "APP首页大分类搜索", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
	
	
	 /**
	    * APP首页轮播图信息
	    * @return
	    */
	   @RequestMapping(value="/banners")
	   @ResponseBody
	   public Map<String,Object> banners( HttpServletRequest request,HttpServletResponse response, String type ){
		    Map<String, Object> resultMap = new HashMap<String,Object>();
		   	String errorCode = PARAM_ERROR_CODE;
		   	String errorMsg = PARAM_ERROR_MSG;
		   	try{
		   		
		   	    //首页轮播图信息
		   		if( StringHelper.isBlank(type) ){
		   			type = "index";
		   		}
		   		resultMap.put(DATA, getMarketBannersByType(type));
		   		errorCode = SUCCESS_ERROR_CODE;
		       	errorMsg = SUCCESS_ERROR_MSG;
		   	}catch(Exception e){
		   		errorCode = SERVER_ERROR_CODE;
		       	errorMsg = SERVER_ERROR_MSG;
		   		logException("IndexInterface", "banners", e.toString(),"APP首页轮播图信息",e);
		   	}
		   	resultMap.put(CODE, errorCode);
		   	resultMap.put(MSG, errorMsg);
		   	isCrrossDomain(response);
		   	return resultMap;
	   }
	  
	   /**
		 * 京东展示页轮播图信息
		 * 
		 * @author 王文鑫
		 * @date 2017年12月22日 上午11:50:49
		 * @param request
		 * @param response
		 * @return
		 */
		@RequestMapping(value = "/models")
		@ResponseBody
		public Map<String, Object> models(HttpServletRequest request, HttpServletResponse response,String type, String token, String appId ) {
			Map<String, Object> resultMap = new HashMap<String, Object>();
			String errorCode = PARAM_ERROR_CODE;
			String errorMsg = PARAM_ERROR_MSG;
			try {
				//首页轮播图信息
		   		if( StringHelper.isBlank(type) ){
		   			type = "index";
		   		}
		   		String isStore = "user";
		   		if( StringHelper.isNotBlank(token) && StringHelper.isNotBlank(appId) ){
		   			UsersMall users = getUsersByTokenAndAppId(token, appId);
		   			if( "002".equals(users.getType()) ){
		   				isStore = "yun";
		   			}
		   		}
				resultMap.put(DATA, getMarketModelsByType(type,isStore));
				errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
			} catch (Exception e) {
				errorCode = SERVER_ERROR_CODE;
				errorMsg = SERVER_ERROR_MSG;
				logException("IndexInterface", "banners", e.toString(), "友惠八大模块", e);
			}
			resultMap.put(CODE, errorCode);
			resultMap.put(MSG, errorMsg);
			isCrrossDomain(response);
			return resultMap;
		}
		
		/**
		 * 获取广告位
		 * 
		 * @author 许小宝
		 * @date 2017年12月22日 下午3:31:52
		 * @param request
		 * @param response
		 * @param address
		 * @return
		 */
		@RequestMapping(value = "/adverts")
		@ResponseBody
		public Map<String, Object> adverts(HttpServletRequest request, HttpServletResponse response,String type,String address) {
			Map<String, Object> resultMap = new HashMap<String, Object>();

			String errorCode = PARAM_ERROR_CODE; // 缺少必填参数
			String errorMsg = PARAM_ERROR_MSG;// 缺少必填参数，返回信息

			try {
				resultMap.put(DATA, getMarketAdvertByTypeAndAddress(type,address));
				errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
			} catch (Exception e) {
				// 服务器异常处理
				errorCode = SERVER_ERROR_CODE;
				errorMsg = SERVER_ERROR_MSG;
				// 打印异常日志
				logException("YhInterface", "advert", e.toString(), "获取广告位", e);
			}
			resultMap.put(CODE, errorCode);
			resultMap.put(MSG, errorMsg);
			isCrrossDomain(response); // 跨域处理
			return resultMap;
		}
	
	/**
	 * APP首页大分类搜索
	 * 
	 * @return
	 */
	@RequestMapping(value = "/modelDetail")
	@ResponseBody
	public Map<String, Object> modelDetail(HttpServletRequest request, HttpServletResponse response, String id, String type ) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			if( StringHelper.isNotBlank(id) && StringHelper.isNotBlank(type) ){
				if( "model".equals(type) ){
					MarketModel marketModel = marketModelsService.get(id);
				    resultMap.put(DATA, getSpuByIdsAndBanner(request,marketModel.getSpuIds(),marketModel.getBanner()));
				}
				if( "advert".equals(type) ){
					MarketAdvert marketModel = marketAdvertService.get(id);
				    resultMap.put(DATA, getSpuByIdsAndBanner(request,marketModel.getSpuIds(),marketModel.getBanner()));
				}
				if( "banner".equals(type) ){
					MarketBanner marketModel = marketBannerService.get(id);
				    resultMap.put(DATA, getSpuByIdsAndBanner(request,marketModel.getSpuIds(),marketModel.getBanner()));
				}
				if( "activity".equals(type) ){
					MarketActivity marketModel = marketActivityService.get(id);
				    resultMap.put(DATA, getSpuByIdsAndBanner(request,marketModel.getSpuIds(),marketModel.getBanner()));
				}
				errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "categorys", e.toString(), "APP首页大分类搜索", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	/**
	 * APP首页大分类搜索
	 * 
	 * @return
	 */
	@RequestMapping(value = "/modelDetailBanner")
	@ResponseBody
	public Map<String, Object> modelDetailBanner(HttpServletRequest request, HttpServletResponse response, String id,String type ) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			if( StringHelper.isNotBlank(id) && StringHelper.isNotBlank(type) ){
				
				if( "model".equals(type) ){
					MarketModel marketModel = marketModelsService.get(id);
					String[] split = new String[]{};
					if( StringHelper.isNotBlank(marketModel.getBanner()) ){
						split = marketModel.getBanner().split(",");
					}
					resultMap.put(DATA, split);
				}
				if( "advert".equals(type) ){
					MarketAdvert marketModel = marketAdvertService.get(id);
					String[] split = new String[]{};
					if( StringHelper.isNotBlank(marketModel.getBanner()) ){
						split = marketModel.getBanner().split(",");
					}
					resultMap.put(DATA, split);
				}
				if( "banner".equals(type) ){
					MarketBanner marketModel = marketBannerService.get(id);
					String[] split = new String[]{};
					if( StringHelper.isNotBlank(marketModel.getBanner()) ){
						split = marketModel.getBanner().split(",");
					}
					resultMap.put(DATA, split);
				}
				if( "activity".equals(type) ){
					MarketActivity marketModel = marketActivityService.get(id);
					String[] split = new String[]{};
					if( StringHelper.isNotBlank(marketModel.getBanner()) ){
						split = marketModel.getBanner().split(",");
					}
					resultMap.put(DATA, split);
				}
				
				errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "categorys", e.toString(), "APP首页大分类搜索", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	/**
	 * APP首页大分类搜索
	 * 
	 * @return
	 */
	@RequestMapping(value = "/modelDetailList")
	@ResponseBody
	public Map<String, Object> modelDetailList(HttpServletRequest request, HttpServletResponse response, String id, String type ) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			if( StringHelper.isNotBlank(id) && StringHelper.isNotBlank(type) ){
				
				if( "model".equals(type) ){
					MarketModel marketModel = marketModelsService.get(id);
					resultMap.put(DATA, getSpuByIds(request,marketModel.getSpuIds()));
				}
				if( "advert".equals(type) ){
					MarketAdvert marketModel = marketAdvertService.get(id);
					resultMap.put(DATA, getSpuByIds(request,marketModel.getSpuIds()));
				}
				if( "banner".equals(type) ){
					MarketBanner marketModel = marketBannerService.get(id);
					resultMap.put(DATA, getSpuByIds(request,marketModel.getSpuIds()));
				}
				if( "activity".equals(type) ){
					MarketActivity marketModel = marketActivityService.get(id);
					resultMap.put(DATA, getSpuByIds(request,marketModel.getSpuIds()));
				}
				errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
			}
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "categorys", e.toString(), "APP首页大分类搜索", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}

	private Map<String, Object> getSpuByIdsAndBanner(HttpServletRequest request, String spuIds, String banner) {
		ArrayList<String> ids = new ArrayList<String>();
		if( StringHelper.isNotBlank(spuIds) ){
			String[] split = spuIds.split(",");
			for( int i=0; i<split.length; i++ ){
				ids.add(split[i]);
			}
		}
		
		Map<String, Object> dataMap = new HashMap<String, Object>();
		GoodsSpuExample example = new GoodsSpuExample();
		Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);// 是否有效
		criteria.andIsShowEqualTo(DBConst.TRUE);// 是否可见
		criteria.andIdIn(ids);
		this.handlePageQueryDefault(request, example);// 分页
		int count = goodsSpuService.count(example);// 总条数
		List<GoodsSpu> list = goodsSpuService.list(example);// 数据list
		
		dataMap.put("banner", banner.split(","));
		dataMap.put("total", count);
		dataMap.put("isMore", isMore(request, count));
		dataMap.put("list", ValueHelper.tranList2MapList(list,spuIgnoreProperties));

		return dataMap;
	}
	
	private Map<String, Object> getSpuByIds(HttpServletRequest request, String spuIds) {
		ArrayList<String> ids = new ArrayList<String>();
		if( StringHelper.isNotBlank(spuIds) ){
			String[] split = spuIds.split(",");
			for( int i=0; i<split.length; i++ ){
				ids.add(split[i]);
			}
		}
		
		Map<String, Object> dataMap = new HashMap<String, Object>();
		GoodsSpuExample example = new GoodsSpuExample();
		Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);// 是否有效
		criteria.andIsShowEqualTo(DBConst.TRUE);// 是否可见
		criteria.andIdIn(ids);
		this.handlePageQueryDefault(request, example);// 分页
		int count = goodsSpuService.count(example);// 总条数
		List<GoodsSpu> list = goodsSpuService.list(example);// 数据list
		
		dataMap.put("total", count);
		dataMap.put("isMore", isMore(request, count));
		dataMap.put("list", ValueHelper.tranList2MapList(list,spuIgnoreProperties));

		return dataMap;
	}



	/**
	 * APP查找友惠，京东，天猫，淘宝等商品信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "/list")
	@ResponseBody
	public Map<String, Object> list(HttpServletRequest request, HttpServletResponse response, String type,
			String keyword, String categoryId, String categoryCode, String orderType, String goodsType ) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			/*
			Map<String, Object> dataMap = new HashMap<String, Object>();

			GoodsSpuExample example = new GoodsSpuExample();
			if (StringHelper.isNotBlank(orderType)) {
				if ("priceDesc".equals(orderType)) {
					example.setOrderByClause("PRICE DESC");
				}
				if ("priceAsc".equals(orderType)) {
					example.setOrderByClause("PRICE ASC");
				}
				if ("commisionDesc".equals(orderType)) {
					example.setOrderByClause("WL_COMMISSION ASC");
				}
				if ("commisionAsc".equals(orderType)) {
					example.setOrderByClause("WL_COMMISSION ASC");
				}
			} else {
				example.setOrderByClause("UPDATE_TIME DESC");
			}

			Criteria criteria = example.createCriteria();
			criteria.andIsEffectiveEqualTo(DBConst.TRUE);// 是否有效
			criteria.andIsShowEqualTo(DBConst.TRUE);// 是否可见

			if (StringHelper.isNotBlank(type)) {
				criteria.andSpuPlatformEqualTo(type);
			}
			if (StringHelper.isNotBlank(keyword)) {
				criteria.andGoodsNameLike("%" + keyword + "%");
			}
			if (StringHelper.isNotBlank(goodsType)) {
				if ("hot".equals(goodsType)) {
					criteria.andIsHotEqualTo("1");
				} else if ("jing".equals(goodsType)) {
					criteria.andIsJingpingEqualTo("1");
				} else if ("special".equals(goodsType)) {
					criteria.andIsSpecialEqualTo("1");
				}else if("fullcut".equals(goodsType)){
					criteria.andIsFullCutEqualTo("1");
				}
			}

			if (StringHelper.isNotBlank(categoryId)) {
				criteria.andCategoryIdEqualTo(categoryId);
			}
			
			if (StringHelper.isNotBlank(categoryCode)) {
				criteria.andCategoryCodeidLike("%"+categoryCode+"%");
			}

			this.handlePageQueryDefault(request, example);// 分页
			int count = goodsSpuService.count(example);// 总条数
			List<GoodsSpu> list = goodsSpuService.list(example);// 数据list

			dataMap.put("total", count);
			dataMap.put("isMore", isMore(request, count));

			dataMap.put("list", ValueHelper.tranList2MapList(list,spuIgnoreProperties));

			*/
			resultMap.put(DATA, getGoodsBySpuFromAndType(request,type,keyword,categoryId,categoryCode,orderType,goodsType) );

			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("GoodsInterface", "index", e.toString(), "APP查找友惠，京东，天猫，淘宝等商品信息", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
}